﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.Data.OleDb;
using QLACQUY.DTO;
using System.Data;

namespace QLACQUY.DAO
{
    class QuyCachDAO:DataAccess
    {
        public IList layDanhSach()
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.DataConnection();
            string strSQL = "select * from QUY_CACH";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            OleDbDataReader dr = cmd.ExecuteReader();
            ArrayList list = new ArrayList();
            while (dr.Read())
            {
                QuyCachDTO quycach = new QuyCachDTO();
                quycach.QuyCach = (string)dr["QuyCachSanPham"];                
                list.Add(quycach);
            }
            dr.Close();
            cn.Close();
            return list;

        }
        public DataTable layBang()
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.DataConnection();
            string strSQL = "select * from QUY_CACH";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            OleDbDataAdapter ad = new OleDbDataAdapter(cmd);
            DataTable tb = new DataTable();
            ad.Fill(tb);
            return tb;
        }
        public int themQuyCach(QuyCachDTO dto)
        {
            OleDbConnection cn = new OleDbConnection();
            cn = this.DataConnection();
            string strSQL = "insert into QUY_CACH values(?)";
            OleDbCommand cmd = new OleDbCommand(strSQL, cn);
            cmd.Parameters.Add("@QuyCachSanPham", OleDbType.WChar);
            cmd.Parameters["@QuyCachSanPham"].Value = dto.QuyCach;
            
            try
            {
                cmd.ExecuteNonQuery();
                return 1;
            }
            catch (System.Exception ex)
            {
                return 0;
            }
            
        }
    }
}
